#include <iostream>
#include <cstring>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
using namespace std;
int main(){
  char *file_a_path="./a.txt";
  char *file_b_path="./b.txt";
  int file_a=open(file_a_path, O_RDONLY);
  int file_b=open(file_b_path, O_RDONLY);
  int file_a_dup=dup(file_a);
  char buf[1024];
  read(file_a_dup,buf,strlen(buf));
  printf("%s",buf);
  cout<<"file_a="<<file_a<<"; file_a_dup="<< file_a_dup<<endl;
  cout<<"**************************************************"<<endl;
  dup2(file_a,file_b);
  read(file_b,buf,strlen(buf));
  printf("%s",buf);
  cout<<"**************************************************"<<endl;
  int flag=fcntl(file_b,F_GETFL);
  cout<<"flag="<<flag<<endl;
  return 0;
}
